//
//  XMChangeMobileView.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/3.
//

#import "XMChangeMobileView.h"

@interface XMChangeMobileView ()

@property (nonatomic, strong) UITextField *mobileTextField;

@end

@implementation XMChangeMobileView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.navView];
    self.navView.backgroundColor = kColorHEX(0xffffff);
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(28.0), kNavagationBarH + KScaleWidth(24.0), self.width - KScaleWidth(28.0), KScaleWidth(46.0)) font:KFontSize(24.0) textColor:kColorHEX(0x221232)];
    titleLabel.text = @"请输入原手机号" ;
    [self addSubview:titleLabel];
    
    UILabel *explainLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.x, titleLabel.maxY, titleLabel.width, KScaleWidth(24.0)) font:KFontSize(14.0) textColor:kColorHEX(0x988DA2)];
    explainLabel.text = @"输入您之前登录所使用的手机号，并确认准确无误";
    [self addSubview:explainLabel];
    
    [self addSubview:self.mobileTextField];
    _mobileTextField.y = explainLabel.maxY + KScaleWidth(90.0);
    UIButton *nextStepBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KBoldFontSize(17.0) frame:CGRectMake((self.width - KScaleWidth(320.0))/2, _mobileTextField.maxY + KScaleWidth(84.0), KScaleWidth(320.0), KScaleWidth(44.0)) title:@"下一步" titleColor:kColorHEX(0x333333)];
    [nextStepBtn setGradientLayerWithLocations:@[@(0), @(1.0)] colors:@[(__bridge id)kColorHEX(0xFFD800).CGColor, (__bridge id)kColorHEX(0xFFE44E).CGColor] startPoint:CGPointMake(0.5, 0.37) endPoint:CGPointMake(0.03, .037)];
    [nextStepBtn addTarget:self action:@selector(nextStepAction:) forControlEvents:UIControlEventTouchUpInside];
    [nextStepBtn setCornerRadius:nextStepBtn.height/2];
    [self addSubview:nextStepBtn];
}

//下一步
- (void)nextStepAction:(UIButton *)button {
    self.nextStepBlock ? self.nextStepBlock(_mobileTextField.text) : nil;
}

#pragma mark - Init
- (UITextField *)mobileTextField {
    if (!_mobileTextField) {
        _mobileTextField = [[UITextField alloc] initWithFrame:CGRectMake((self.width - KScaleWidth(320.0))/2, 0, KScaleWidth(320.0), KScaleWidth(44.0))];
        _mobileTextField.font = KFontSize(16.0);
        _mobileTextField.placeholder = @"请输入手机号码";
        _mobileTextField.backgroundColor = kColorHEX(0xF5F3F7);
        _mobileTextField.keyboardType = UIKeyboardTypePhonePad;
        [_mobileTextField setCornerRadius:_mobileTextField.height/2];
        
        UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScaleWidth(84.0), _mobileTextField.height)];
        UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(16.0) frame:CGRectMake(0, 0, KScaleWidth(70.0), leftView.height) title:@"+86" titleColor:kColorHEX(0x221232) image:@""];
        [leftView addSubview:leftBtn];
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(KScaleWidth(71.0), (leftView.height - KScaleWidth(28.0))/2, 1, KScaleWidth(28.0))];
        lineView.backgroundColor = kColorHEX(0xCBC3D2);
        [leftView addSubview:lineView];
        _mobileTextField.leftViewMode = UITextFieldViewModeAlways;
        _mobileTextField.leftView = leftView;
    }
    return _mobileTextField;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
